////////////////////////////////////////////////////////
//                                                    //
//                  Tarea #5		                  //
//        Instituto Tecnologico de Costa Rica         //
//        Analisis Numerico para Ingenieria           //
//        Profesor: Pablo ALvarado                    //
//        Estudiantes: Gia Yao Chen                   //
//                     Alejandro Morales              //
//        II Semestre, 2012                           //
////////////////////////////////////////////////////////

#include <cmath>
#include <iomanip>
#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <vector>

using boost::numeric::ublas::matrix;
using namespace std;

matrix<double> crearMatriz(double n){
	matrix<double> A(n,n);
	for (int i = 0; i < n; i++){
		cout << "| ";
		for (int j = 0; j < n; j++){
			A(i,j) = i+j+2;
			cout << A(i,j) << " ";
		}
		cout << "|" << endl;
	}
	cout << "" << endl;
	return A;
}

double sum(double i, double j, double k, matrix<double> L, matrix<double> U){
	return 0;
}

matrix<double> descLU(matrix<double> A, int n){
	matrix<double> L(n,n);
	matrix<double> U(n,n);
	
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (i == j){
				U(i,j) = 1;
			}	
			if (j == 0){
				L(i,j) = A(i,j);
				U(j,i) = A(j,i)/L(0,j);
			}
			/*double result = 0;
			double k = 1;
			while (k < j-1){
				result += L(i,k)*U(k,j);
				i++;
				k++;
			}
			L(i,j) = A(i,j) - result;
			*/
			//U(j,i) = A(j,i)/L(i,j);
			
			//if (i == 0){
				
				//U(i,j) = A(i,j);
			//}			
		}
	}
	
	for (int i = 0; i < n; i++){
		cout << "l ";
		for (int j = 0; j < n; j++){
			cout << L(i,j) << " ";
		}
		cout << "l" << endl;
	}
	
	cout << "" << endl;
	
	for (int i = 0; i < n; i++){
		cout << "u ";
		for (int j = 0; j < n; j++){
			cout << U(i,j) << " ";
		}
		cout << "u" << endl;
	}
			
	return L;
}

int main(){
	matrix<double> Prueba = crearMatriz(4);
	
	
	vector<double> V(4);
	vector<double> F(4);
	
	for (unsigned int i = 0; i < V.size(); i++){
		V[i] = Prueba(i,1);
		F[i] = Prueba(1,i);

		cout << V[i] << ",";
		cout << F[i] << "/";
	}
	
	cout << " " << endl;
	
	descLU(Prueba,4);
	return 0;
}



template <class T>
  matrix <T> Matrix (T a, T b) {
	  
  return (Matrix);
}



